import Vue from "vue"
import Router from "vue-router"
Vue.use(Router)

const Home = () => import("views/Home.vue")
const Share = () => import("views/Share.vue")
const Profit = () => import("views/Profit.vue")
const Mine = () => import("views/Mine.vue")
const Login = () => import("views/Login.vue")
const Register = () => import("views/Register.vue")

const UserInfo = ()=> import("views/Mine/UserInfo.vue")
const Alipay = () => import("views/Mine/Alipay.vue")

const ForgetPassword = () => import("views/ForgetPassword.vue")
const RealName = ()=>import("views/RealName.vue")
const ManualAudit= () => import("views/ManualAudit.vue")
const IntelligenceName =() =>import("../views/IntelligenceName.vue")


const OpenWeb = () => import("views/OpenWeb.vue")


const routes = [
    {
        path:"/",
        redirect:"/login"
    },
    {
        path: "/openweb",
        name: "OpenWeb",
        component: OpenWeb
    },
    {
        path:"/intelligenceName",
        name:"IntelligenceName",
        component:IntelligenceName
    },
    {
        path:"/alipay",
        name:"Alipay",
        component:Alipay
    },
    {
        path:"/manualaudit",
        name:"ManualAudit",
        component:ManualAudit
    },
    {
        path:"/realName",
        name:"RealName",
        component:RealName
    },
    {
        path:"/userinfo",
        name:"UserInfo",
        component:UserInfo
    },
    {
        path:"/forgetpassword",
        name:"ForgetPassword",
        component:ForgetPassword
    },
    {
        path:"/home",
        component:Home
    },
    {
        path:"/share",
        component:Share
    },
    {
        path:"/profit",
        component:Profit
    },
    {
        path:"/mine",
        component:Mine
    },
    {
        path:"/login",
        name:"Login",
        component:Login
    },
    {
        path:"/register",
        name:"Register",
        component:Register
    },
]

const router = new Router({
    routes,
    mode:"history"
})
router.beforeEach((to,from,next)=>{
    // to 将要访问那个位置
    // from  从哪个路径过来
    // next  放行
    if(to.path == "/login" ) return next();
    const toke = window.localStorage.getItem("token");
    if(!toke) return next("/login");
    next();

})

export default router